﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="../bootstrap/js/jquery.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <!--[if lt IE 9]>
      <script src="bootstrap/js/html5shiv.min.js"></script>
      <script src="bootstrap/js/respond.min.js"></script>
    <![endif]-->
    <script src="../config.js"></script>
    <script src="../bootstrap/js/Common.js"></script>
    <script src="../bootstrap/js/controls.js"></script>
    <script type="text/javascript">

        $(function () {
            var formOption = {
                items: [
                    { name: "terminalID", title: "编号", field: "terminalID", type: "text", readonly: GetUrlParam("mode") != "1" },
                    { name: "model", title: "型号", field: "model", type: "text" },
                    { name: "name", title: "名称", field: "name", type: "text" },
                    { name: "localAddress", title: "本机地址", field: "localAddress", type: "text" },
                    { name: "remoteAddress", title: "访问地址", field: "remoteAddress", type: "text"  },
                    { name: "accessKey", title: "访问密码", field: "accessKey", type: "text"  },
                    { name: "protocol", title: "协议", field: "protocol", type: "text" },
                    { name: "version", title: "软件版本", field: "version", type: "text"  },
                    { name: "coordinate", title: "位置坐标", field: "coordinate", type: "text"  },
                    { name: "address", title: "地址", field: "address", type: "text" },
                    { name: "timeoutSecs", title: "心跳超时秒数", field: "timeoutSecs", type: "text" },
                    { name: "extras", title: "扩展信息", field: "extras", type: "text" }
                ]
            };
            $(".form-horizontal").form(formOption).load(host_name + "terminal/single?id=" + GetUrlParam("id"),
                function () {
                    if (GetUrlParam("mode") == "1") {
                        document.getElementById("terminalID").addEventListener("keyup",
                            function () {
                                this.value = this.value.replace(/[^\w\-]/g, '');
                            }
                        );
                      
                    }
                });
        });
        function Save() {
            var action = GetUrlParam("mode") == "1" ? "add" : "edit";
            if (action=="add"&& $("#terminalID").val() == "") {
                alert("终端编号不能为空！");
                return "dnone";
            }
            else {
                if (action == "edit") {
                    var tmpInput = $("<input  class='form-control' type='text' name='id' field='id' id='id'/>");
                    tmpInput.attr("value", GetUrlParam("id"));
                    $(".form-horizontal").append(tmpInput);
                }
                return $(".form-horizontal").form().save(host_name + "terminal/" + action);
            }
        }
    </script>
</head>
<body>
    <div class="container">
        <form class="form-horizontal"></form>
    </div>
</body>
</html>